#include<bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
const int MOD = 998244353;
int qpow(int x,int p){
    int res = 1;
    while(p){
        if(p & 1){
            res = 1ll*res*x%MOD;
        }
        x = 1ll*x*x%MOD;
        p >>= 1;
    }
    return res;
}
const int G = 3,GINV = qpow(G,MOD - 2),MB = 18;
int jc[N],jc_1[N];
int f[N];
vector<int> trs[20];
vector<int> bginv[20];
vector<int> bg[20];
void init(){
    trs[0] = vector<int>(1,0);
    for(int i = 1;i <= MB;i++){
        trs[i] = vector<int>(1<<i);
        bg[i] = vector<int>(1<<i - 1);
        bginv[i] = vector<int>(1<<i - 1);
        for(int j = 0;j < i;j++){
            for(int k = 1<<j;k < (1<<j + 1);k++){
                trs[i][k] = trs[i][k - (1<<j)] | (1<<(i - j - 1));
            }
        }
        bg[i][0] = 1;
        bginv[i][0] = 1;
        int o1 = qpow(G,(MOD - 1)/(1<<i));
        int o2 = qpow(GINV,(MOD - 1)/(1<<i));
        for(int j = 1;j < (1<<i - 1);j++){
            bg[i][j] = 1ll*bg[i][j - 1]*o1%MOD;
            bginv[i][j] = 1ll*bginv[i][j - 1]*o2%MOD;
        }
    }
}
vector<int> FFT(const vector<int> &val,int tot,int lgt,vector<int> *base = bg){
    vector<int> res(tot);
    for(int j = 0;j < tot;j++){
        if(trs[lgt][j] < val.size()){
            res[j] = val[trs[lgt][j]];
        }
    }
    for(int i = 1;i<=lgt;i++){
        int len = 1<<i;
        int hlen = len/2;
        for(int j = 0;j < tot;j += len)
        {
            for(int k = j;k < j + hlen;k++){
                int va = res[k],vb = 1ll*base[i][k - j]*res[k + hlen]%MOD;
                res[k] = (va + vb)%MOD;
                res[k + hlen] = (va - vb + MOD)%MOD;
            }
        }
    }
    return res;
}

vector<int> IFFT(const vector<int> &val,int tot,int lgt){
    return FFT(val,tot,lgt,bginv);
}
vector<int> operator*(const vector<int> &va,const vector<int> &vb){
    int n = va.size() - 1;
    int m = vb.size() - 1;
    int tot = 1;
    int lgt = 0;
    while(tot <= n + m){
        tot<<=1;
        lgt++;
    }
    vector<int> FA = FFT(va,tot,lgt),FB = FFT(vb,tot,lgt);
    for(int i = 0;i < tot;i++){
        FA[i] = 1ll*FA[i]*FB[i]%MOD;
    }
    FA = IFFT(FA,tot,lgt);
    FA.resize(n + m + 1);
    int inv = qpow(tot,MOD - 2);
    for(int &v : FA){
        v = 1ll*v*inv%MOD;
    }
    return FA;
}
void sf(int l,int r){
    //cerr<<l<<' '<<r<<'\n';
    if(l == r){
        if(l == 1){
            f[l] = 1;
        }else if(l == 2){
            f[l] = 2;
        }else{
            f[l] = (f[l] + 1ll*(l - 2)*f[l - 1]%MOD)%MOD;
        }
        return;
    }
    int mid = (l + r)/2;
    sf(l,mid);
    if(l == 1){
        vector<int> f1(mid + 1);
        for(int i = 3;i <= mid;i++){
            f1[i] =f[i];
        }
        vector<int> f2(mid + 1);
        for(int i = 3;i <= mid;i++){
            f2[i] = 1ll*f[i]*(i - 2)%MOD;
        }
        vector<int> res = f1*f2;
        for(int i = mid + 1;i <= r;i++)
        {
            f[i] = (f[i] + res[i + 1])%MOD;
        }
    }else{
        vector<int> f1(r - l + 2);
        for(int i = 3;i <= r - l + 1;i++){
            f1[i] = f[i];
        }
        vector<int> f2(mid - l + 1);
        for(int i = l;i <= mid;i++){        
            f2[i - l] = 1ll*f[i]*(i - 2)%MOD;
        }
        vector<int> res = f1*f2;
        //f1 = vector<int>(mid - l + 2);
        //f2 = vector<int>(mid - l + 1);
        for(int i = mid + 1;i <= r;i++){
            f[i] = (f[i] + res[i - l + 1])%MOD;
        }
        for(int i = 3;i <= r - l + 1;i++){
            f1[i] = 1ll*f[i]*(i - 2)%MOD;
        }
        for(int i = l;i <= mid;i++){
            f2[i - l] = f[i];
        }
        res = f1*f2;
        for(int i = mid + 1;i <= r;i++){
            f[i] = (f[i] + res[i - l + 1])%MOD;
        }
    }
    
    sf(mid + 1,r);
}
void buildf(int n){
    init();
    sf(1,n);
    /*
    for(int i = 1;i<=n;i++){
        cout<<f[i]<<' ';
    }
    cout<<'\n';
    
    f[1] = 1;
    f[2] = 2;
    for(int i = 3;i <= n;i++){
        f[i] = 1ll*(i - 2)*f[i - 1]%MOD;
        for(int j = 2;j <= i - 2;j++){
            f[i] = (f[i] + 1ll*f[j + 1]*f[i - 1 - (j - 1)]%MOD*(i - 1 - (j - 1) - 2)%MOD)%MOD;
        }
    }
    for(int i = 1;i<=n;i++){
        cout<<f[i]<<' ';
    }
    cout<<'\n';
    */
}
int a[N];
int val[N];
vector<int> bian[N];
int lcur = 1;
int S[N],sp;
int ans = 1;
int cnt[N];
int n;
void solve(){
    for(int i = 1;i<=n;i++){
        cin>>a[i];
    }
    if(a[n] != n){
        cout<<0<<'\n';
        return;
    }
    for(int i = 1;i<=n;i++){
        bian[i].clear();
        cnt[i] = 1;
    }
    S[++sp] = n;
    for(int i = n - 1;i >= 1;i--){
        while(i < S[sp] - a[S[sp]] + 1){
            sp--;
        }
        if(i - a[i] + 1 < S[sp] - a[S[sp]] + 1){
            cout<<0<<'\n';
            return;
        }
        cnt[S[sp]]++;
        S[++sp]= i;
    }
    int ans = 1;
    for(int i = 1;i<=n;i++){
        ans = 1ll*ans*f[cnt[i]]%MOD;
    }
    cout<<ans<<'\n';
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    cin>>n;
    buildf(n);
    //cerr<<f[n]<<'\n';
    jc[0] = 1;
    for(int i = 1;i<=n;i++){
        jc[i] = 1ll*jc[i - 1]*i%MOD;
    }
    jc_1[n] = qpow(jc[n],MOD - 2);
    for(int i = n - 1;i >= 1;i--){
        jc_1[i] = 1ll*jc_1[i + 1]*(i + 1)%MOD;
    }
    jc_1[0] = 1;
    jc[0] = jc_1[0] = 1;
    while(T--){
        solve();
    }
}
/*
dp[x] = x! 
*/